<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cart3</title>
</head>
<body>
<h1>购物车</h1>  
<table>  
    <tr>  
        <th>商品名称</th>  
        <th>数量</th>  
        <th>单价</th>  
        <th>小计</th>  
    </tr>  
    <%  
        List<CartItem> cartItems = (List<CartItem>) request.getAttribute("cartItems");  
        for (CartItem item : cartItems) {  
    %>  
    <tr>  
        <td><%= item.getName() %></td>  
        <td><%= item.getQuantity() %></td>  
        <td><%= item.getPrice() %></td>  
        <td><%= item.getQuantity() * item.getPrice() %></td>  
    </tr>  
    <% } %>  
    <tr>  
        <td colspan="3">总计：</td>  
        <td><%= calculateTotalPrice(cartItems) %></td>  
    </tr>  
</table>  
<a href="checkout">结算</a>  
<%!  
    // 计算总价的方法，这里为了简化放在JSP中，实际项目中可以放在后端处理  
     double calculateTotalPrice(List<CartItem> cartItems) {  
        double total = 0;  
        for (CartItem item : cartItems) {  
            total += item.getQuantity() * item.getPrice();  
        }  
        return total;  
    }  
%>  

<%@ page contentType="text/html;charset=UTF-8" language="java" %>  
<html>  
<head>  
    <title>结算成功</title>  
</head>  
<body>  
<h1>结算成功</h1>  
<p>您需要支付的总金额为：<%= request.getAttribute("totalPrice") %></p>  

</body>  
</html>
